<?php
/*
+--------------------------------------------------------------------------
|   phpBIZbiz v 2.0 full version
|   ========================================
|   by taft@wjl.cn
|   http://www.phpbiz.cn
|   all rights reserved
+---------------------------------------------------------------------------
|
|   > 
|   > 最后修改日期：2005-9-9
|   > 
|
+--------------------------------------------------------------------------
*/

class admin_skin
{
	var $base_url;
	var $td_wd=array();
	var $td_span;          //统计整个表的span
	var $td_header = array();
    var $img_url;

	function admin_skin()
	{   
		global $CONF,$INCOME;
		$this -> base_url = $CONF['admin_url']."admin.".$CONF['php_ext']."?";
		$this -> img_url  = $CONF['admin_url'].'img_sys';

	}
	
	function get_css()
	{
		return "<style type='text/css'>
					BODY {
							font-size: 12px;
							color:#000;
							padding:0px;
							margin:0px 5px 0px 5px;
						  }
						  
				    TABLE, TD, TR {
							color:#000;
							font-size: 12px;
						  }
						  
					a:link, a:visited, a:active  { color:#000055 }
					a:hover                      { color:#333377;text-decoration:underline }
					
					#maintop { font-size:18px;
					           color:#FFF;
					           font-weight:bold;
					           letter-spacing:-1px;
					           padding:9px 5px 9px 5px;
					           border:1px solid #345487;
					           background-image: url({$this->img_url}/tile_back.gif);
					         }
					
					
					#nav { font-size:12px;margin:8px 0px 8px 0px;color:#3A4F6C;font-weight:bold;}
					#nav a:link, #nav  a:visited, #nav a:active { font-weight:bold;font-size:12px; }
					
					#submenu   { border:1px solid #BCD0ED;background-color: #DFE6EF;font-size:12px;margin:3px 0px 3px 0px;color:#3A4F6C;font-weight:bold;}
					#submenu a:link, #submenu  a:visited, #submenu a:active { font-weight:bold;font-size:12px;text-decoration: none; color: #3A4F6C; }

					
					.tableborder { border:1px solid #345487;background-color:#FFF;width:100% }
					
					.offdiv { font-size:12px;font-weight:bold }
					
					form { display:inline }
					input { vertical-align:middle }
					
					img  { vertical-align:middle }
					
					.titlemedium { border:1px solid #FFF; font-weight:bold; color:#3A4F6C; padding:7px 0px 7px 2px; background-image: url({$this->img_url}/tile_sub.gif) }
					.titlemedium  a:link, .titlemedium  a:visited, .titlemedium  a:active  { text-decoration: underline; color: #3A4F6C }
					
					.maintitle { font-size:12px; vertical-align:middle;font-weight:bold; color:#FFF; letter-spacing:1px; padding:8px 0px 8px 5px; background-image: url({$this->img_url}/tile_back.gif) }
					.maintitle a:link, .maintitle  a:visited, .maintitle  a:active { text-decoration: none; color: #FFF }
					.maintitle a:hover { text-decoration: underline }
					
					.pformstrip { background-color: #D1DCEB; color:#3A4F6C;font-weight:bold;padding:5px;margin-top:1px }
					
					#normal      { font: 10px Verdana; color:#333333 }
					
					#detail { font-size:12px; color: #333333 }
					
					#subtitle { font-size:16px; color:#FF9900; font-weight:bold }
					#smalltitle { font-size:12px; color:#FF9900; font-weight:bold }
					
					#table1 {  background-color:#FFFFFF; width:100%; align:center; border:1px solid black }
					
					.tdrow1 { background-color:#EEF2F7;
					          border-bottom:1px solid #D1DCEB;
					          border-right:1px solid #D1DCEB ;
					          border-top:1px solid #FFF;
					          border-left:1px solid #FFF;
					        }
					
					.subforum { background-color:#DFE6EF }
					
					.tdrow2 { background-color:#F5F9FD;
							  border-bottom:1px solid #D1DCEB;
					          border-right:1px solid #D1DCEB;
					          border-top:1px solid #FFF;
					          border-left:1px solid #FFF;
					        }
					
					.catrow { font-weight:bold; height:24px; line-height:150%; color:#4C77B6; background-image: url({$this->img_url}/tile_sub.gif); }
					.catrow2 { font-size:12px; font-weight:bold; line-height:150%; color:#4C77B6; background-color:#D3DFEF; }
					
					.copy { color:#000; font-size:12px; border-top:1px solid #000; margin-bottom:10px; padding:6px;  margin-left:auto;margin-right:auto; text-align:center; }
					
					#nav { color:#000000; font-size:12px }
					
					#description { color:#000000; font-size:12px }
					
					#memgroup { border:1px solid #777777 }
					
					#mgred   { border:1px solid #777777; background-color: #f5cdcd }
					#mggreen { border:1px solid #777777; background-color: #caf2d9 }
					#mgblue  { border:1px solid #777777; background-color: #DFE6EF }
					
					#green    { background-color: #caf2d9 }
					#red      { background-color: #f5cdcd }
					
					#button   { border:1px solid #4C77B6;background-color: #DFE6EF; font-size:12px }
					
					#editbutton   { background-color: #DDDDDD; color: #000; font-size:12px }
					
					.fauxbutton   { border:1px solid #4C77B6;
								    background-color: #DFE6EF;
								    font-size:12px;
								    font-weight:bold;
								    padding:3px;
								    margin:6px;
								  }
								  
					.darksep { background-color: #B1BECE; color:#4C77B6; height:5px }
					
					.fauxbutton a:link, .fauxbutton  a:visited, .fauxbutton  a:active { font-size:12px;font-weight:bold; }
					
					.textinput { background-color: #FFF; color:?#000; font-size:12px; padding:2px; border:2px inset #BCD0ED; }
					
					.dropdown { background-color: #FFF; color:?#000; font-size:12px; padding:2px;  border:2px inset #BCD0ED; }
					
					.multitext { background-color: #FFF; color:?#000; font-size:12px; padding:2px;  border:2px inset #BCD0ED; }
					
					.jmenu, .jmenubutton { vertical-align:middle;
										  background-color: #FFF;
										  border:1px solid #345487;
										  font-size:12px;
										 }
										 
					#jwrap { border:1px solid #BCD0ED;background-color: #DFE6EF;font-size:12px;margin:3px 0px 3px 0px;color:#3A4F6C;font-weight:bold;padding:8px }
					
				  </style>";

	}

	function get_js_show()
	{
         return " 
		       <script language='JavaScript'>
		       function showinfo(d)
			   {
	
	             if (d==0){
		          document.all('show1').style.display	= '';
		          document.all('show2').style.display	= 'none';
		          document.all('show3').style.display	= 'none';
	             }else{
		          document.all('show1').style.display	= 'none';
		          document.all('show2').style.display	= '';
		          document.all('show3').style.display	= '';
	             }
               } </script>";
	}

	function get_js_confirmLink()
	{
		return "function confirmLink(theLink, theSqlQuery)
				{
					 // Confirmation is not required in the configuration file
					 // or browser is Opera (crappy js implementation)
			      
					 var is_confirmed = confirm('是否要进行批量删除操作？');
					

				     return is_confirmed;
				} ";
	}

	function  get_top($title,$info="")
	{
				$css = $this -> get_css();
				$js = $this -> get_js_confirmLink();  // 不能直接嵌套入
       return "  <html><head><title>phpBIZ中文完全版</title>
		          <meta http-equiv=\"Pragma\" content=\"no-cache\">
				  <meta http-equiv=\"Cache-Control\" content=\"no-cache\">
				  <meta http-equiv=\"Expires\" content=\"Mon, 06 May 1996 04:57:00 GMT\">
				  $css
                  <script type='text/javascript'>
					function ShowHide(id1, id2) {
					  if (id1 != '') expMenu(id1);
					  if (id2 != '') expMenu(id2);
					}
              		$js;					
					function expMenu(id) {
					  var itm = null;
					  if (document.getElementById) {
						itm = document.getElementById(id);
					  } else if (document.all){
						itm = document.all[id];
					  } else if (document.layers){
						itm = document.layers[id];
					  }
					
					  if (!itm) {
					   // do nothing
					  }
					  else if (itm.style) {
						if (itm.style.display == \"none\") {
						  itm.style.display = \"\";
						}
						else {
						  itm.style.display = \"none\";
						}
					  }
					  else {
						itm.visibility = \"show\";
					  }
					}
					function multi_page_jump( url_bit, total_posts, per_page )
					{
					  pages = 1; cur_st = parseInt(\"\"); cur_page  = 1;
					  if ( total_posts % per_page == 0 ) { pages = total_posts / per_page; }
					   else { pages = Math.ceil( total_posts / per_page ); }
					  msg = \"Choose a page between 1 and\" + \" \" + pages;
					  if ( cur_st > 0 ) { cur_page = cur_st / per_page; cur_page = cur_page -1; }
					  show_page = 1;
					  if ( cur_page < pages )  { show_page = cur_page + 1; }
					  if ( cur_page >= pages ) { show_page = cur_page - 1; }
					   else { show_page = cur_page + 1; }
					  userPage = prompt( msg, show_page );
					  if ( userPage > 0  ) {
						  if ( userPage < 1 )     {    userPage = 1;  }
						  if ( userPage > pages ) { userPage = pages; }
						  if ( userPage == 1 )    {     start = 0;    }
						  else { start = (userPage - 1) * per_page; }
						  self.location.href = url_bit + \"&st=\" + start;
					  }
					}
				 </script>
				</head>
		          <body leftmargin='0' topmargin='0' bgcolor='#ffffff' marginheight='0' marginwidth='0'>
				 <div id='maintop'>$title</div>
				 <table id='submenu' cellspacing='6' width='100%'>
				 <tbody><tr>
				  <td><a href='{$this->base_url}act=menu&show=all' target='menu'>展开菜单</a> &middot; <a href='{$this->base_url}act=menu&show=none' target='menu'>折叠菜单</a></td>
				 </tr>
				 </tbody></table>
				 <!--NAV-->
				 <div id='description'>$info</div>
				 <br>
		";

	}

	function frame_set()
	{
		return "<html>
		   			 <head><title>phpBIZ中文完全版</title></head>
					   <frameset cols='185, *' frameborder='no' border='0' framespacing='0'>
					   	<frame name='menu' noresize scrolling='auto' src='{$this->base_url}act=menu&show=none'>
					   	<frame name='body' noresize scrolling='auto' src='{$this->base_url}act=index'>
					   </frameset>
				   </html>";
	}


   /**
	*     table 头 html
	*
	*     @param string 表标题
	*	  @param array  表属性
	*     @access public
	*/


	function table_head($title="",$desc="", $table_property = array( "align" =>"center", "border"=>"0", "cellpadding"=>"5", "width"=>"100%", "cellspacing"=>"0" ))
	{
		

		$property_str = $this->property_compile( $table_property );
		
		$this -> td_span = count($this->td_header);   //统计整个跨度
		
		//构造表标题
		$head_html .= "  <div class='tableborder'>
						<div class='maintitle'>$title</div>";

		$head_html .= " <table {$property_str}>";	
 		
		if ( $desc != "" )
		{
				$head_html .= "<div class='pformstrip'>$desc</div>\n";
		}
       
		//构造表头<th>
		foreach( $this -> td_header as $header )
		{
			if( $text = $header[0] )
					
				$head_html.= "<th class='titlemedium' colspan='{$header[2]}' witdh='{$header[1]}'>$text</th>";
			
		}

		
		return $head_html;
	}

	
   /**
	*     table 尾 html
	*
	*     @access public
	*/

	function table_end()
	{
		$this -> td_header = array();
		return "</table></div>";
	}

   /**
	*     table 每一行td的 html
	*
	*     @access public
	*/
    

	function table_row( $array, $td_property="",$align='left',$trstr="" )
	{
	    
		if( is_array( $td_property ) ) $ex = $this -> property_compile( $td_property );

		if( is_array($array) )
		{
			$col = count($array);
            
			for( $i=0; $i<$col; $i++ )
			{				
				$class = $i % 2 ? 'tdrow2' :'tdrow1';    //css样式
				
				if( is_array($array[$i]) )
				{
					$text = $array[$i][0];
					$span = $array[$i][1]; 
					$td_html .= "<td class='$class' colspan='$span' align='$align' $ex >$text</td>";
				}
				else
				{
					$width = $this -> td_header[$i][1];
					$td_html .= "<td class='$class' width='$width' align='$align' $ex >$array[$i]</td>";
				}
			}
			$row_html="<tr $trstr>".$td_html."</tr>";
		}
	    return $row_html;
	
	}// 简单的泛型td

	function td_basic($text="",$align="left",$id="tdrow1") 
	{
	
		$html    = "";
		$colspan = "";
		
		if ($text != "")
		{
			if ($this->td_span > 0)   //
			{
				$colspan = " colspan='".$this->td_span."' ";
			}
						
			$html .= "<tr><td align='$align' class='$id'".$colspan.">$text</td></tr>\n";
		}
		
		return $html;
	
	}

	function td_spacer() {
	
		if ($this->td_colspan > 0)
		{
			$colspan = " colspan='".$this->td_colspan."' ";
		}
	
		return "<tr><td".$colspan."><img src='img/blank.gif' height='7' width='1'></td></tr>";
	
	}

	
	/*---------------------------------
			表单构造函数组(post method for safe)
			@表单名(string)
			@表单体部(string)
	---------------------------------*/
	function form_head( $form_name="" )
	{
           $head = " <form action='' method='post' name='{$form_name}'>";

		   return $head;
	}

	function form_end( $value='提交',$ex='' )
	{
       	$html= "<td colspan='$this->td_span' align='middle' class='pformstrip'>";
		if( $value ) $html .="<input type='submit' value='$value' id='button' accesskey='s' $ex >";
		return $html."</form>";
	}
	

	function form_element( $element_array="", $ex_property=""  )
	{
		if( is_array( $ex_property ) ) $ex = $this -> property_compile( $ex_property );
		if( is_array($element_array) )
		{
			foreach( $element_array as $type => $n_v )
			$form_ele = "<input type='{$type}' name='{$n_v[0]}' value='{$n_v[1]}' {$ex}>";
		}
		return $form_ele;
	}

	function form_input( $name, $value ="" , $type = "text" )
	{
		return $this -> form_element( array( $type => array( $name, $value ) )  );
    }

	function form_droplist($name, $list=array(), $default_val="", $js="") {
	
		if ($js != "")
		{
			$js = ' '.$js.' ';
		}
	
		$html = "<select name='$name'".$js." class='dropdown'>\n";
		
		foreach ($list as $k => $v)
		{
		
			$selected = "";
			
			if ( ($default_val != "") and ($v[0] == $default_val) )
			{
				$selected = ' selected';
			}
			
			$html .= "<option value='".$v[0]."'".$selected.">".$v[1]."</option>\n";
		}
		
		$html .= "</select>\n\n";
		
		return $html;
	
	
	}

	//+--------------------------------------------------------------------
	
	function form_yes_no( $name, $default_val="", $js=array() ) 
	{
	
		$y_js = "";
		$n_js = "";
		
		if ( $js['yes'] != "" )
		{
			$y_js = $js['yes'];
		}
		
		if ( $js['no'] != "" )
		{
			$n_js = $js['no'];
		}
	
		$yes = "是 &nbsp; <input type='radio' name='$name' value='1' $y_js id='green'>";
		$no  = "否 &nbsp; <input type='radio' name='$name' value='0' $n_js id='red'>  ";
		
		
		
		if ($default_val == 1)
		{
			
			$yes = "是 &nbsp; <input type='radio' name='$name' value='1'$y_js checked id='green'>";
		}
		else
		{
			$no  = "否 &nbsp; <input type='radio' name='$name' value='0' checked $n_js id='red'>";
		}
		
		
		return $yes.'&nbsp;&nbsp;&nbsp;'.$no;
		
	}
	
	function multiple_select( $name,$value )
	{
		$html = "<select name='".$name."' class='forminput' size='8' multiple='multiple'>";
		
		foreach( $value as $key => $value )
		{
			$html .= "<option value='$key'>{$value}</option>";
		}

		$html .= "</select>";

		return $html;
	}

	/*---------------------------------
	  
	  -------------------------------*/
    function property_compile( $res )
	{
		foreach( $res as $key => $value )
	    {
			$str = $key."='".$value."' ";
		    $property .= $str;
		}
		return $property;
	}

	/*--------------------------------
			左边菜单生成
	--------------------------------*/

	function menu_top()
	{
		global $CONF;

		return "<html>
		          <head><title></title>
		          <style type='text/css'>
		          	TABLE, TR, TD     { font-size: 12px; color:#000 }
					BODY      {
								 font: 12px Verdana;
								 color:#000;
								 background-color:#FFF;
								 margin:0px 3px 0px 3px;
								 padding:0px;
							  }
					a:link, a:visited, a:active  { color:#000 }
					a:hover                      { text-decoration:underline }
					
					img { vertical-align:middle }
					#title  { font-size:12px; font-weight:bold; line-height:150%; color:#FFFFFF; height: 24px; background-image: url({$this->img_url}/tile_back.gif); }
					#title  a:link, #title  a:visited, #title  a:active { text-decoration: none; color : #555555 }
					
					.desc {
							font-size:12px;
							color: #000;
							background-color:#DFE6EF;
							padding:2px 0px 2px 5px;
							line-height:1.2em;
						   }
					
					.plain {
							font-size:12px;
							color: #000;
							background-color:#EEF2F7;
							padding:2px 0px 2px 5px;
							line-height:1.7em;
						   }
					
					.tableborder { border:1px solid #345487;background-color:#FFF; }
					
					.cattitle  {
								font-size:12px;
								font-weight:bold;
								line-height:150%;
								background-color:#C4DCF7;
								color:#000;
								padding:5px 4px 5px 5px;
								background-image: url({$this->img_url}/tile_sub.gif);
								border-bottom:1px solid #345487;
							   }
					.cattitle  a:link, .cattitle  a:visited, .cattitle  a:active { text-decoration: underline; color:#000; }
					
				  </style>
				  
				  </head>
				 <body marginheight='0' marginwidth='0' leftmargin='0' topmargin='0' bgcolor='#FFF'>
				 <div align='center'></div>
				 <div class='tableborder'>
				  <div class='plain'>
				   <img src='{$this->img_url}/item.gif' border='0' alt='' valign='absmiddle'>&nbsp;<a href='{$this->base_url}act=menu&show=all' target='menu'>展开</a>&middot;<a href='{$this->base_url}act=menu&show=none' target='menu'>折叠</a> 菜单
				   <br /><img src='{$this->img_url}/item.gif' border='0' alt='' valign='absmiddle'>&nbsp;<a href='{$this->base_url}act=index' target='body'>管理</a>&middot;<a href='http://www.phpBIZ.cn' target='body'>phpBIZ</a> 首页
				   <br /><img src='{$this->img_url}/item.gif' border='0' alt='' valign='absmiddle'>&nbsp;<a href='{$this->base_url}act=pwd' target='body' >修改密码</a><br><img src='{$this->img_url}/item.gif' border='0' alt='' valign='absmiddle'>&nbsp;<a href='{$this->base_url}&code=logout' target='_top' >退出登陆</a>
				  </div>
				 </div>
				 <br />
				";
	}

	function menu_foot() 
	{
		return "</body></html>";
	}

	function menu_tree()
	{
		global $INCOME, $TREE, $CATS, $SKIN, $DESC;
		
		$html  = "";
		$links = "";
		
			
		foreach($CATS as $cid => $name)
		{
			
		
			if ( preg_match( "/(?:^|,)$cid(?:,|$)/", $INCOME['show'] ) )
			{
			
				  foreach($TREE[ $cid ] as $pid => $pdata)
				  {
				  						
					  $links .= $SKIN->menu_link($pdata[1], $pdata[0]);
					                             //  url      name     
				  }
				  
				  $html .= $SKIN->menu_expand( $name, $links, $cid );   //展开
				  unset($links);		
			}
			else
			{    
				$html .= $SKIN->menu_collapse( $name, $cid, $DESC[ $cid ] );  //收缩
			}
			
		}
		return $html;

	}

	function menu_expand( $name="", $links="", $id = "" )
	{
		global $INCOME;
	
		return "<a name='cat$id'></a>
				<div class='tableborder'>
				  <div class='cattitle'>
				    <a href='{$this->base_url}act=menu&show={$INCOME['show']}&out=$id' target='menu'><img src='{$this->img_url}/minus.gif' border='0' alt='折叠类别' title='折叠类别'></a>
				    <a href='{$this->base_url}act=menu&show={$INCOME['show']}&out=$id' target='menu'>$name</a>
				  </div>
				  <div class='plain'>$links</div>   
				</div>
				<br />\n";//$links = 子类
	}

	function menu_collapse( $name="", $id = "", $desc="" )
	{
		global $INCOME;
	
		return "<div class='tableborder'>
				  <div class='cattitle'>
				    <a href='{$this->base_url}act=menu&show=,{$INCOME['show']},$id#cat$id' target='menu'><img src='{$this->img_url}/plus.gif' border='0' alt='展开类别' title='展开类别'></a>
				    <a href='{$this->base_url}act=menu&show=,{$INCOME['show']},$id#cat$id' target='menu'>$name</a>
				  </div>
				  <div class='desc'>$desc</div>    
				</div>
				<br />\n";//描述
	}

	function menu_link( $url="", $name="" )
	{
	
		return "<img src='{$this->img_url}/item.gif' border='0' alt='' valign='absmiddle'>&nbsp;<a href='{$this->base_url}$url' target='body' style='text-decoration:none'>$name</a><br />";


	}

	function get_foot() 
	{
		
		return "<br />
				<div class='copy' align='center'><a href='http://www.phpbiz.cn' title='phpBIZ' target='_blank'>phpBIZ V3.0</a> &copy; 2005-2007 &nbsp;<br /> <a href='http://wjl.cn' target='_blank'>WJL STUDIO</a></div>
				 </body>
				 </html>";
	}

	function wrap_nav($links)
	{	// 添加图标
		return "\n<div id='nav'><img src='{$this -> img_url}/nav.gif' border='0' title='ACP Navigation'>&nbsp;$links</div>\n";
	}

	
	function build_pagelinks($data)
	{

		$work = array();
		
		$section = ($data['leave_out'] == "") ? 2 : $data['leave_out'];  // Number of pages to show per section( either side of current), IE: 1 ... 4 5 [6] 7 8 ... 10
	
		$work['pages']  = 1;
		
		if ( ($data['TOTAL_POSS'] % $data['PER_PAGE']) == 0 )
		{
			$work['pages'] = $data['TOTAL_POSS'] / $data['PER_PAGE'];
		}
		else
		{
			$number = ($data['TOTAL_POSS'] / $data['PER_PAGE']);
			$work['pages'] = ceil( $number);
		}        //分多少页
		
		
		$work['total_page']   = $work['pages'];
		$work['current_page'] = $data['CUR_ST_VAL'] > 0 ? ($data['CUR_ST_VAL'] / $data['PER_PAGE']) + 1 : 1;
		
	
		if ($work['pages'] > 1)
		{
			$work['first_page'] = "分页：";
			
			for( $i = 0; $i <= $work['pages'] - 1; ++$i )
			{
				$RealNo = $i * $data['PER_PAGE'];
				$PageNo = $i+1;
				
				if ($RealNo == $data['CUR_ST_VAL'])
				{
					$work['page_span'] .= "&nbsp;<b>[{$PageNo}]</b>";
				}
				else
				{
					
					if ($PageNo < ($work['current_page'] - $section))
					{
						$work['st_dots'] = "&nbsp;<a href='{$data['BASE_URL']}&amp;st=0' title='首页'} 1'>&laquo; 首页</a>&nbsp;...";
						continue;
					}
					
					// If the next page is out of our section range, add some dotty dots!
					
					if ($PageNo > ($work['current_page'] + $section))
					{
						$work['end_dots'] = "...&nbsp;<a href='{$data['BASE_URL']}&amp;st=".($work['pages']-1) * $data['PER_PAGE']."' title='总页数 {$work['pages']}'>末页 &raquo;</a>";
						break;
					}
					
					
					$work['page_span'] .= "&nbsp;<a href='{$data['BASE_URL']}&amp;st={$RealNo}'>{$PageNo}</a>";
				}
			}
			
			$work['return']    = $work['first_page'].$work['st_dots'].$work['page_span'].'&nbsp;'.$work['end_dots'];
		}
		else
		{
			$work['return']    = $data['L_SINGLE'];
		}
	
		return $work['return'];
	}
					



}
?>